import { useQuery } from "react-query";
import { StudentColumns } from "../types";
import { studentKeys } from "./query-keys";

function useStudentListQuery(){
	// const quertClient = new QueryClient()
	return useQuery({
		queryKey: studentKeys.lists(),
		queryFn: async ({queryKey}) => {
			const res: StudentColumns[] = await fetch('http://localhost:5000/students',{
				headers: {
					'Content-Type': 'application/json',
				}
			}).then(res => res.json())
			if(res.length > 0){
				// quertClient.defaultQueryOptions()
				return res
			}else{
				return Promise.reject(res)
			}
		}
	})
}

export default useStudentListQuery;